package com.pub.cloud.system.status.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pub.cloud.system.status.config.LinuxOsParmConfig;
import com.pub.cloud.system.status.util.LinuxSystemTool;

import io.swagger.annotations.ApiOperation;
import net.minidev.json.JSONObject;

@RequestMapping("/linuxSystemStatus")
@RestController
public class LinuxSystemStatusController {

	private static final Logger logger = LogManager.getLogger(LinuxSystemStatusController.class);
	
	@Autowired
	private LinuxOsParmConfig linuxOsParmConfig;
	
	
	@ApiOperation(value = "获取linux基本信息", notes = "获取linux基本信息")
	
	
	@GetMapping(path = "/baseInfo")
	public String getLinuxBaseInfo() {
		Map<String,Object> result=new HashMap<String, Object>();
		result.put("diskUsage", LinuxSystemTool.getDiskInfoExp());
		result.put("menUsage", LinuxSystemTool.getMemInfoExp());
		try {
			result.put("CPUUsage", LinuxSystemTool.getCpuInfo());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		result.get("diskUsage");
		return JSONObject.toJSONString(result).toString();
	}
	@GetMapping(path = "/diskInfo")
	public String getLinuxDiskInfo() {
//		System.out.println(linuxOsParmConfig.getDiskAlarmNum());
		int Threshold=linuxOsParmConfig.getDiskAlarmNum();
		Map<String,Object> result=new HashMap<String, Object>();
		result.put("diskUsage", LinuxSystemTool.getDiskAlertExp(linuxOsParmConfig.getDiskAlarmNum()));
//		result.put("diskUsage", LinuxSystemTool.getDiskInfoExp());
		return JSONObject.toJSONString(result).toString();
	}
}
